package com.nd.bdc.presto.websocket.disruptor;


import com.alibaba.fastjson.JSON;
import com.lmax.disruptor.EventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;


@Component
public class MessageEventHandler implements EventHandler<MessageEvent> {

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @Override
    public void onEvent(MessageEvent messageEvent, long l, boolean b) {
        String messageData = JSON.toJSONString(messageEvent.getMessageData());
        messagingTemplate.convertAndSendToUser(messageEvent.getChannel(),"/pullMessage",messageData);
    }
}
